Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[Gluon] Support None argument in HybridBlock #16280

Merged
merged 4 commits into from
Sep 27, 2019

Conversation

sxjscience
Copy link
Member

@sxjscience sxjscience commented Sep 25, 2019

Description

Solves #13247

We will later consider to support dict, OrderedDict, namedtuple and customized python classes in Gluon 2.0 @leezu @junrushao1994

Support the following way of writing the hybrid_forward:

class Foo(HybridBlock):
    def hybrid_forward(self, F, a, b):
        if a is None and b is not None:
            return b
        elif b is None and a is not None:
            return a
        elif a is not None and b is not None:
            return a + b
        else:
            raise NotImplementedError

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • HybridBlock argument as None, tests

@sxjscience sxjscience changed the title [Gluon] Support None as the argument for HybridBlock [Gluon] Support None argument in HybridBlock Sep 26, 2019
Copy link
Member

@wkcn wkcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix! LGTM : )

support None as arguments in HybridBlock

Update block.py

fix

fix

Update test_gluon.py

Update test_gluon.py
Copy link
Contributor

@haojin2 haojin2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@haojin2 haojin2 merged commit 01ca278 into apache:master Sep 27, 2019
@szha
Copy link
Member

szha commented Sep 27, 2019

@eric-haibin-lin FYI on the merge.

larroy pushed a commit to larroy/mxnet that referenced this pull request Sep 28, 2019
* support none in hybridblock argument

support None as arguments in HybridBlock

Update block.py

fix

fix

Update test_gluon.py

Update test_gluon.py

* fix bug

* fix bug

* test case of default values
sojiadeshina pushed a commit to sojiadeshina/incubator-mxnet that referenced this pull request Sep 30, 2019
* support none in hybridblock argument

support None as arguments in HybridBlock

Update block.py

fix

fix

Update test_gluon.py

Update test_gluon.py

* fix bug

* fix bug

* test case of default values
@sxjscience sxjscience deleted the support_none_hybrid_block branch October 10, 2019 00:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants